#!/usr/bin/env python
# -*- coding:utf-8 -*-
# -----------------
#  Author: 王荣雯
#　Create date: '2017/8/4' '下午3:19'
# -----------------

import os

from PySide import QtGui,QtCore

#from ui.ui_export_atom_dlg import Ui_ExportDialog
from ui import ui_export_atom_dlg
reload(ui_export_atom_dlg)

import settings
import atom_export
reload(atom_export)

class AtomExportDialog(QtGui.QDialog):
    """

    """
    def __init__(self, parent=None):
        super(AtomExportDialog, self).__init__(parent=parent)

        self.ui = ui_export_atom_dlg.Ui_ExportDialog()

        self.setupGui()
        self.setupActions()

    def setupGui(self):
        self.ui.setupUi(self)
        self.ui.pose_toolBox.setCurrentIndex(0)
        self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)

    def setupActions(self):
        self.button_list = [self.ui.px_pushButton,self.ui.py_pushButton,self.ui.pz_pushButton,self.ui.walk_pushButton,
                       self.ui.nx_pushButton,self.ui.ny_pushButton,self.ui.nz_pushButton,self.ui.relax_pushButton,
                       self.ui.pypx_pushButton,self.ui.pynx_pushButton,self.ui.nypx_pushButton,self.ui.nynx_pushButton,
                       self.ui.pypz_pushButton,self.ui.pynz_pushButton,self.ui.nypz_pushButton,self.ui.nynz_pushButton,
                       self.ui.pzpx_pushButton,self.ui.pznx_pushButton,self.ui.nzpx_pushButton,self.ui.nznx_pushButton]
        for button in self.button_list:
            button.clicked.connect(self.poseAction)

        self.ui.ch_comboBox.currentIndexChanged.connect(self.change_button_color)

    def poseAction(self):
        sender = self.sender()
        ex = "ex"
        character = self.ui.ch_comboBox.currentText()
        action_name = sender.objectName().split('_')[0]
        atom_export.export_import_ani(ex, character, action_name)

        self.change_button_color()

    def change_button_color(self):
        character = self.ui.ch_comboBox.currentText()
        for button in self.button_list:
            file_name = os.path.join(settings.ANIM_FILE_PATH, character, button.objectName().split('_')[0]+'.atom')
            if os.path.exists(file_name):
                button.setStyleSheet("background-color: rgb(51, 163, 114);")
            else:
                button.setStyleSheet("background-color: rgb(64, 64, 64);")

    def showEvent(self, *args, **kwargs):
        super(AtomExportDialog, self).showEvent(*args, **kwargs)
        self.change_button_color()


if __name__ == '__main__':
    import sys

    app = QtGui.QApplication(sys.argv)

    d = AtomExportDialog()
    d.show()

    app.exec_()


